import ImEnum from '../../enums/index.js'
import TransUtil from '../../config/transform-util/index.js'
import ImStg from '../../utils/ImStorage.js'
import Vue from "vue";
const ImUser = {
	state: {
		userListState: 0,//更新 通讯录数据
	},
	mutations: {
		imUserListDataKey(state, obj) {
			Vue.set(state,'chatListState',state.chatListState++)
		},

	},
	actions: {
		/**
		 * @param {Object} payload
		 * @param {Object}  obj 为List 数组
		 */
		imUserListDataKey: function(payload,obj) {
			if(obj){
				/**
				 * 装换 后台dto 适配前端dto
				 */
				if(obj){
					obj = TransUtil.setContactsDto(obj)
				}
				let map = ImStg.getImStorageSync(ImEnum.ImStorageEnum.contactsList)
				if(map){
						map[obj.id] = obj
				}else{
					map = obj
				}
				ImStg.setImStorageSync(ImEnum.ImStorageEnum.contactsList,map)
				payload.commit("imUserListDataKey", obj);
			}
			
		},
	},
	getters: {
		imUserListGetter(state){//获取会话列表
			let temp = state.userListState//这个是用于监听 会话列表是否变更了的，不能删除
			let map = ImStg.getImStorageSync(ImEnum.ImStorageEnum.contactsList)
			return map
		},
	}
}
export default ImUser
